package org.example.mybatis.mapper;

import org.apache.ibatis.annotations.*;
import org.example.mybatis.model.UserInfo;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:做渐进主义的改良派,不做完没注意的速成派
 * User: XALEXC
 * Date: 2024-12-23
 * Time: 17:49
 */
@Mapper
public interface UserInfoMapper {
    @Select("select id, username, password, age, gender, phone, delete_flag, create_time, update_time" +
            " from userinfo")
    List<UserInfo> selectAll();

    @Select("select * from userinfo where id= ${id}")
    UserInfo selectOne(Integer id);

    @Select("select * from userinfo where username= '${username}'")
    UserInfo selectByName(String username);

    @Select("select * from userinfo where id= #{userid}")
    UserInfo selectOne2(@Param("userid") Integer id);

    // 增
    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into userinfo (username,password,age,gender,phone)" +
            "values (#{username},#{password},#{age},#{gender},#{phone})")
    Integer insert(UserInfo userInfo);

    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into userinfo (username,password,age,gender,phone)" +
            "values (#{username},#{password},#{age},#{gender},#{phone})")
    Integer insert2(@Param("userInfo") UserInfo userInfo);

    // 删
    @Delete("delete from userinfo where id=#{id}")
    Integer delete(Integer id);

    // 改
    @Update("update userinfo set age=#{age} where id=#{id}")
    Integer update(UserInfo userInfo);

    /**
     * 排序
     * @param sort
     * @return
     */
    @Select("select * from userinfo order by id ${sort}")
    List<UserInfo> selectUserinfoMapper(String sort);

    @Select("select * from userinfo where username like '%${username}%'")
    List<UserInfo> selectUserByLike(String username);

}